package com.neihe.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.neihe.entity.dto.file.DeleteFileDTO;
import com.neihe.entity.dto.file.RestoreFileDTO;
import com.neihe.entity.vo.file.UserFileVO;
import com.neihe.service.IRecycleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 回收站模块
 *
 * @author neihe
 * @since 2025-01-04
 */
@Slf4j
@RestController
public class RecycleController {

    @Autowired
    private IRecycleService recycleService;

    /**
     * 查询用户的回收站文件集合
     *
     * @return 结果
     */
    @GetMapping("/api/recycle/private/list")
    public List<UserFileVO> recycles() {
        Long userId = StpUtil.getLoginIdAsLong();
        return recycleService.recycles(userId);
    }

    /**
     * 删除的文件批量还原
     *
     * @param requestParam 请求参数
     */
    @PostMapping("/api/recycle/private/restore")
    public void restore(@Valid @RequestBody RestoreFileDTO requestParam) {
        recycleService.restore(requestParam);
    }

    /**
     * 彻底删除文件
     *
     * @param requestParam 请求参数
     */
    @PostMapping("/api/recycle/private/delete")
    public void delete(@Valid @RequestBody DeleteFileDTO requestParam) {
        requestParam.setUserId(StpUtil.getLoginIdAsLong());
        recycleService.delete(requestParam);
    }
}
